package step3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 서버 프로그램 
 * 클라이언트로부터 메세지를 입력받는 프로그램 구현 
 * 1. ServerSocket(5432)
 * 2. while(true)
 * 3. accept():Socket
 * 4. socket.getInputStream()
 * 5. InputStreamReader()
 * 6. BufferedReader
 * 7. readLine() 
 * 8. 입력받은 메세지를 아이피와 출력 
 * 9. close() 
 * @author kosta-00-kangsa-001
 *
 */
public class TestServer3 {
	public void go() throws IOException{
		ServerSocket ss=new ServerSocket(5432);
		System.out.println("**Server 실행중**");
		while(true){
			Socket socket=ss.accept();
			InputStreamReader ir=new InputStreamReader(socket.getInputStream());
			BufferedReader br=new BufferedReader(ir);
			String ip=socket.getInetAddress().toString();
			try{
				String mess=br.readLine();
				System.out.println("["+ip+"]님 메세지:"+mess);
			}catch(IOException ie){
				System.out.println(ie.getMessage()+"["+ip+"]님  입력 실패..");
			}
			br.close();
			socket.close();
		}
	}
	public static void main(String[] args) {
		TestServer3 server=new TestServer3();
		try {
			server.go();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}







